package org.yatr.ttcn.rt.impl;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.StringTokenizer;

import org.etsi.ttcn.tci.QualifiedName;
import org.etsi.ttcn.tci.TciBehaviourId;
import org.etsi.ttcn.tci.TciModuleId;
import org.etsi.ttcn.tci.TciTestCaseId;

public class QualifiedNameYatr implements QualifiedName,TciModuleId, TciTestCaseId
			,TciBehaviourId
{
	String baseName;
	String moduleName;
	
	public QualifiedNameYatr(String moduleName, String baseName) {
		this.baseName = baseName;
		this.moduleName = moduleName;
	}
	
	public QualifiedNameYatr(String fullName) {
	      StringTokenizer ST = new StringTokenizer(fullName, ".");
	      moduleName = ST.nextToken();
	      baseName = ST.nextToken();
	}
	
	public int hashCode() {
		return baseName.hashCode() + moduleName.hashCode();
	}

	public boolean equals(Object o){
		return this.hashCode() == o.hashCode();
	}

	public String getBaseName() {
		return baseName;
	}

	public String getModuleName() {
		return moduleName;
	}

	public void setBaseName(String baseName) {
		this.baseName = baseName;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}
	
	public String toString() {
		return moduleName+"."+baseName;
	}
	
	//Test this class
	public static void main(String[]args) {
		Map<QualifiedName, String> t = new LinkedHashMap<QualifiedName, String>();
		t.put(new QualifiedNameYatr("Module1.type1"), "lvj");
		t.put(new QualifiedNameYatr("Module2.type2"), "lvj2");
		t.put(new QualifiedNameYatr("Module3.type3"), "lvj3");
		t.put(new QualifiedNameYatr("Module4.type4"), "lvj4");
		t.put(new QualifiedNameYatr("Module5.type5"), "lvj5");
		
		System.out.println(t.size());
		System.out.println(t);
		
		QualifiedName qn = new QualifiedNameYatr("Module4.type4");
		System.out.println(t.containsKey(qn));
		System.out.println(t.get(qn));
		System.out.println(qn);
		
		QualifiedName qn2 = new QualifiedNameYatr("Module4.type4");
		System.out.println(qn2.equals(qn));

	}

}
